import { createApp } from 'vue'

import Cookies from 'js-cookie'

import ElementPlus from 'element-plus'
import locale from 'element-plus/lib/locale/lang/zh-cn' // 中文语言

import '@/assets/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'
import directive from './directive' // directive


// 注册指令
import plugins from './plugins' // plugins
import { download,exportExcelByWeb,exportExcelSumByWeb,exportExcelAllSheetByWeb,exportExcelAllSheetSumByWeb } from '@/utils/request'

// svg图标
import 'virtual:svg-icons-register'
import SvgIcon from '@/components/SvgIcon'
import elementIcons from '@/components/SvgIcon/svgicon'

import './permission' // permission control

import { useDict } from '@/utils/dict'
import { parseTime, resetForm, addDateRange, handleTree, selectDictLabel, selectDictLabels } from '@/utils/xpp'
import { addDate,flexColumnWidth } from '@/utils/util'
import { getCurrTime, getSummary, columnsCal,treeFindPath} from '@/utils/lz'
import { getSysDate,getSysTime,addSysDate} from "@/utils/lz";

import {formRule} from "@/utils/validate";


// 分页组件
import Pagination from '@/components/Pagination'
// 自定义表格工具组件
import RightToolbar from '@/components/RightToolbar'
// 文件上传组件
import FileUpload from "@/components/FileUpload"
// 图片上传组件
import ImageUpload from "@/components/ImageUpload"
// 图片预览组件
import ImagePreview from "@/components/ImagePreview"
// 自定义树选择组件
import TreeSelect from '@/components/TreeSelect'
// 字典标签组件
import DictTag from '@/components/DictTag'

import {
  formatAmountEmpty,
  formatAmountZero,
  formartNumber,
  formartTableP2,
  formartTableP4,
  formartFormP4,
  formartTablePercentP16,
  formartTablePercentP12,
  formartTablePercentP8,
  formartTablePercentP4,
  formartTablePercentP2,
  formartTablePercentP3,
  formartEmptyTableP2,
  formartEmptyTablePercentP2
} from '@/utils/numberUtil'
import xTable from "@/lz/base/xTable";
import selectTable from "@/lz/base/selectTable";
import baseCombox from "@/lz/base/baseCombox";
import dictCombox from "@/lz/base/dictCombox"
import underlyer from "@/lz/base/underlyer";
import number from "@/lz/base/number";

// main.ts中全局引入
import DataVVue3 from '@kjgl77/datav-vue3'

import XEUtils from 'xe-utils'
import {
  // 全局对象
  VXETable,

  // 表格功能
  Filter,
  Edit,
  Menu,
  Export,
  Keyboard,
  Validator,

  // 可选组件
  Icon,
  Column,
  // Colgroup,
  // Grid,
  // Tooltip,
  Toolbar,
  // Pager,
  // Form,
  // FormItem,
  // FormGather,
  // Checkbox,
  // CheckboxGroup,
  // Radio,
  // RadioGroup,
  // RadioButton,
  // Switch,
  // Input,
  // Select,
  // Optgroup,
  // Option,
  // Textarea,
  // Button,
  // Modal,
  // List,
  // Pulldown,

  // 表格
  Table
} from 'vxe-table'
import zhCN from 'vxe-table/es/locale/lang/zh-CN'

// 按需加载的方式默认是不带国际化的，自定义国际化需要自行解析占位符 '{0}'，例如：
VXETable.setup({
  i18n: (key, args) => XEUtils.toFormatString(XEUtils.get(zhCN, key), args)
})

function useTable (app) {
  // 表格功能
  app.use(Filter)
  .use(Edit)
  .use(Menu)
  .use(Export)
  .use(Keyboard)
  .use(Validator)

  // 可选组件
  app.use(Icon)
      .use(Column)
      // .use(Colgroup)
      // .use(Grid)
      // .use(Tooltip)
      .use(Toolbar)
      // .use(Pager)
      // .use(Form)
      // .use(FormItem)
      // .use(FormGather)
      // .use(Checkbox)
      // .use(CheckboxGroup)
      // .use(Radio)
      // .use(RadioGroup)
      // .use(RadioButton)
      // .use(Switch)
      // .use(Input)
      // .use(Select)
      // .use(Optgroup)
      // .use(Option)
      // .use(Textarea)
      // .use(Button)
      // .use(Modal)
      // .use(List)
      // .use(Pulldown)

      // 安装表格
      .use(Table)

  // 给 vue 实例挂载内部对象，例如：
  // app.config.globalProperties.$XModal = VXETable.modal
  // app.config.globalProperties.$XPrint = VXETable.print
  // app.config.globalProperties.$XSaveFile = VXETable.saveFile
  // app.config.globalProperties.$XReadFile = VXETable.readFile
}
import socket from '@/utils/socket'
// 引入模块后自动生效
const app = createApp(App)
app.config.globalProperties.socket = socket
// 全局方法挂载
app.config.globalProperties.useDict = useDict
app.config.globalProperties.download = download
app.config.globalProperties.exportExcel = exportExcelByWeb
app.config.globalProperties.exportSumExcel = exportExcelSumByWeb
app.config.globalProperties.exportExcelAllSheet=exportExcelAllSheetByWeb
app.config.globalProperties.exportExcelAllSumSheet=exportExcelAllSheetSumByWeb
app.config.globalProperties.parseTime = parseTime
app.config.globalProperties.resetForm = resetForm
app.config.globalProperties.handleTree = handleTree
app.config.globalProperties.addDate =addDate
app.config.globalProperties.flexColumnWidth=flexColumnWidth
app.config.globalProperties.addDateRange = addDateRange
app.config.globalProperties.getSysDate = getSysDate
app.config.globalProperties.getSysTime = getSysTime
app.config.globalProperties.addSysDate = addSysDate
app.config.globalProperties.selectDictLabel = selectDictLabel
app.config.globalProperties.selectDictLabels = selectDictLabels
app.config.globalProperties.getCurrTime = getCurrTime
app.config.globalProperties.formRuleConstant = formRule
app.config.globalProperties.getSummary = getSummary
app.config.globalProperties.columnsCal = columnsCal
app.config.globalProperties.treeFindPath = treeFindPath
app.config.globalProperties.formatAmountEmpty=formatAmountEmpty
app.config.globalProperties.formatAmountZero=formatAmountZero
app.config.globalProperties.formartNumber = formartNumber
app.config.globalProperties.formartFormP4 = formartFormP4
app.config.globalProperties.formartTableP2 = formartTableP2
app.config.globalProperties.formartTableP4 = formartTableP4
app.config.globalProperties.formartTablePercentP4 = formartTablePercentP4
app.config.globalProperties.formartTablePercentP8 = formartTablePercentP8
app.config.globalProperties.formartTablePercentP12 = formartTablePercentP12
app.config.globalProperties.formartTablePercentP16 = formartTablePercentP16
app.config.globalProperties.formartTablePercentP2 = formartTablePercentP2
app.config.globalProperties.formartTablePercentP3 = formartTablePercentP3
app.config.globalProperties.formartEmptyTableP2 = formartEmptyTableP2
app.config.globalProperties.formartEmptyTablePercentP2=formartEmptyTablePercentP2
// 全局组件挂载
app.component('DictTag', DictTag)
app.component('Pagination', Pagination)
app.component('TreeSelect', TreeSelect)
app.component('FileUpload', FileUpload)
app.component('ImageUpload', ImageUpload)
app.component('ImagePreview', ImagePreview)
app.component('RightToolbar', RightToolbar)
// 全局自定义组件挂载
app.component('xTable', xTable)
app.component('selectTable', selectTable)
app.component('baseCombox', baseCombox)
app.component('dictCombox', dictCombox)
app.component('underlyer', underlyer)
app.component('number', number)
app.use(DataVVue3)

app.use(router)
app.use(store)
app.use(plugins)
app.use(elementIcons)
app.component('svg-icon', SvgIcon)
useTable(app)

directive(app)

// 使用element-plus 并且设置全局的大小
app.use(ElementPlus, {
  locale: locale,
  // 支持 large、default、small
  size: Cookies.get('size') || 'small'
})

app.mount('#app')
